package yuejian_07.yuejian_07.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.List;

import yuejian_07.yuejian_07.R;
import yuejian_07.yuejian_07.RetrofitListener;
import yuejian_07.yuejian_07.adapter.NoticeListAdapter;
import yuejian_07.yuejian_07.javabean.Notice;
import yuejian_07.yuejian_07.model.NoticeModel;

public class NoticeListActivity extends Activity implements RetrofitListener<List<Notice>> {
    private RecyclerView recyclerView;
    private ImageView img_return;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice_list);
        initViews();
        initEvents();
        getNoticelist();
    }
    private void initViews(){

        recyclerView= (RecyclerView)findViewById(R.id.rv_list1);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        img_return=(ImageView) findViewById(R.id.img_return);
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }
    private void initEvents(){
        img_return.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    void getNoticelist(){
        NoticeModel noticeModel=new NoticeModel();
        noticeModel.noticelist(this);
    }

    @Override
    public void onSuccess(List<Notice> data ){

        System.out.printf("data");
        recyclerView.setAdapter(new NoticeListAdapter(NoticeListActivity.this,data));
    }

    @Override
    public void onFail(){ Toast.makeText(this, "网络发生错误", Toast.LENGTH_SHORT).show();}
}
